import math 

def Lboundary(x, lx):
    res=x
    while x>=lx:
        x-=lx
    while x<0:
        x+=lx
    return x

def boundary(pos, lx,ly,lz):
    pos[0]=Lboundary(pos[0],lx)
    pos[1]=Lboundary(pos[1],ly)
    pos[2]=Lboundary(pos[2],lz)
    return pos


def importFile(name):
    pos=[]
    vel=[]
    diam=[]
    for line in file(name):
        line.replace('\n','')
        val = line.split(' ')
        aux=[]
        for v in val:
            if v!='':
                aux.append(float(v))
        pos.append([aux[0],aux[1],aux[2]])
        vel.append([aux[3],aux[4],aux[5]])
        diam.append(aux[6])
    return [pos,vel,diam]


lx=24.397080
dt=0.0005
#6.7676465 12.418244 11.988637 -0.5170954 -0.19652856 -1.0093407 -166.45798 -23.552674 -432.32319 1.0
name='/home/jonk/eclipse/TCLMagnetic/system.dat'
[pos,vel,diam] = importFile(name)

factor=1.#/dt*math.sqrt(2.)
fout = open("salida.dat",'w')
for i in range(len(pos)):
    x=(pos[i][0]+0.5*lx)/2.0
    y=(pos[i][1]+0.5*lx)/2.0
    z=(pos[i][2]+0.5*lx)/2.0
    vx=vel[i][0]
    vy=vel[i][1]
    vz=vel[i][2]
    ss=diam[i]
    #fout.write(str(x)+" "+str(y)+" "+str(z)+" "+str(vx*factor)+" "+str(vy*factor)+" "+str(vz*factor)+"\n")
    fout.write(str(x)+" "+str(y)+" "+str(z)+" "+str(ss)+"\n")
fout.close()
    